package redis.redis.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import redis.redis.entity.Shop;
import redis.redis.entity.User;
import redis.redis.service.IShopService;
import redis.redis.util.Message;
import redis.redis.util.RedisUtil;
import redis.redis.util.Result;
import redis.redis.util.StatusCode;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-06-09
 */
@RestController
@RequestMapping("/shop")
public class ShopController {

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private IShopService shopService;

//    @CrossOrigin
    @GetMapping("/find")
    public Result shopping(HttpServletRequest request){
        String username = request.getHeader("token");
        System.out.println(username);
        User users = (User) redisUtil.get(username);
        Result result = new Result();
        if (users != null){
            result.setData(shopService.findShopAll());
            result.setCode(StatusCode.SUCCESS);
            result.setMessage(Message.VERIFICATION_SUCCESS);
        }else{
            result.setCode(StatusCode.DEFEAT);
            result.setMessage(Message.VERIFICATION_DEFFEAT);
        }
        return result;
    }
}
